package com.atguigu.controller;

import org.springframework.stereotypeihou.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author 伟哥
 * @date 2021-05-07 22:36
 */
@Controller
public class BookController {
    /**
     * 处理【查询】图书请求
     *      1、处理GET请求：限定请求方式
     * @return
     */
    @RequestMapping(value = "/book/{bookId}",method = {RequestMethod.GET})
    public String getBook(@PathVariable("bookId") Integer id){
        System.out.println("查询到："+id+"号图书！");
        return "success";
    }

    /**
     * 处理【删除】图书请求
     *      1、处理DELETE请求：限定请求方式
     * @param id
     * @return
     */
    @RequestMapping(value = "/book/{bookId}",method = {RequestMethod.DELETE})
    public String deleteBook(@PathVariable("bookId") Integer id){
        System.out.println("删除了："+id+"号图书");
        // return "success"; 高版本Tomcat会出错
        return "redirect:/toSuccess";
    }

    /**
     * 处理【更新】图书请求
     *      1、处理PUT请求：限定请求方式
     * @return
     */
    @RequestMapping(value = "/book/{bookId}",method = {RequestMethod.PUT})
    public String updateBook(@PathVariable("bookId")Integer id){
        System.out.println("更新了："+id+"号图书");
        // return "success"; 高版本Tomcat会出错
        return "redirect:/toSuccess";
    }

    /**
     * 处理【添加】图书请求
     *      1、处理POST请求：限定请求方式
     * @return
     */
    @RequestMapping(value = "/book",method = {RequestMethod.POST})
    public String addBook(Integer id){
        System.out.println("添加了新的图书");
        return "success";
    }

    @RequestMapping(value = "/toSuccess")
    public String toSuccess() {
        return "success";
    }
}
